package com.binsoft.ndtta;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

public class WebViewFragment extends Fragment
{
 	private WebView webView = null;
	private Bundle webViewBundle = null;
	
	@SuppressLint("SetJavaScriptEnabled")
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
		    Bundle savedInstanceState)
	{
		LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.web_page_layout,
				container, false);

		webView = (WebView) ll.findViewById(R.id.webView);
		webView.setWebViewClient(new WebViewClient() {
	            ProgressDialog prDialog;

	            @Override
	            public void onPageFinished(WebView view, String url) {
	                super.onPageFinished(view, url);
	                prDialog.dismiss();
	            }

				@Override
				public void onPageStarted(WebView view, String url,
						Bitmap favicon)
				{
					super.onPageStarted(view, url, favicon);
					
	                prDialog = ProgressDialog.show(getActivity(), "Please wait...", "Connecting to ndtta");
				}
	        });
	     
		webView.getSettings().setLoadWithOverviewMode(true);
		webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
		webView.getSettings().setUseWideViewPort(true );
		webView.getSettings().setJavaScriptEnabled(true);
	    webView.getSettings().setBuiltInZoomControls(true);
	    webView.getSettings().setSupportZoom(true);
	    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);   
	    webView.getSettings().setAllowFileAccess(true); 
	    webView.getSettings().setDomStorageEnabled(true);

        if (webViewBundle == null) 
        {
        	try
        	{
        		webView.loadUrl("http://www.ndtta.co.uk");
    		}
        	catch (Exception e)
        	{
				e.printStackTrace();
			}
		} 
        else 
        {
			webView.restoreState(webViewBundle);
		}

	    return ll;
	}

	@Override
	public void onPause()
	{
		super.onPause();
		
		webViewBundle = new Bundle();
		
		webView.saveState( webViewBundle );
	}
}
